//
//  SISSOneSignView.m
//  SISSAPP
//
//  Created by 优房网 on 2017/9/5.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSOneSignView.h"
#import <SDWebImage/UIImageView+WebCache.h>

@interface SISSOneSignView ()

/* titleLabel */
@property (weak, nonatomic) UILabel *titleLabel;
/// 名字Label
@property (weak, nonatomic) UILabel *titleNameLabel;
/// 签字imageView
@property (weak, nonatomic) UIImageView *imageView;

/* 签署日期Label */
@property (weak, nonatomic) UILabel *signTimeTitleLabel;
/// 签署日期Label
@property (weak, nonatomic) UILabel *signTimeLabel;

@end
@implementation SISSOneSignView

- (void)setTitle:(NSString *)title {
    _title = title;
    self.titleLabel.text = title;
}

- (void)setTitleName:(NSString *)titleName {
    _titleName = titleName;
    self.titleNameLabel.text = titleName;
}

- (void)setSignImgUrl:(NSString *)signImgUrl {
    _signImgUrl = signImgUrl;
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:signImgUrl]];
}
- (void)setSignTime:(NSString *)signTime {
    _signTime = signTime;
    self.signTimeLabel.text = signTime;
}

#pragma mark - UI
- (void)initUI {
    [super initUI];
    
    // 甲方
    UILabel *titleLabel = [UILabel yyr_labelWithText:@"【甲方】：" fontSize:16 textColor:SECONDARY_TEXT_COLOR];
    [self addSubview:titleLabel];
    self.titleLabel = titleLabel;
    
    UILabel *titleNameLabel = [UILabel yyr_labelWithText:@" " fontSize:16 textColor:MAIN_TEXT_COLOR];
    titleNameLabel.numberOfLines = 0;
    titleNameLabel.font = [UIFont boldSystemFontOfSize:16];
    titleNameLabel.text = @" ";
    [self addSubview:titleNameLabel];
    self.titleNameLabel = titleNameLabel;
    
    // 甲方签名
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.backgroundColor = COLOR(0xD2E0EB);
    [self addSubview:imageView];
    self.imageView = imageView;
    
    // 甲方签署日期
    UILabel *signTimeTitleLabel = [UILabel yyr_labelWithText:@"签署日期：" fontSize:16 textColor:SECONDARY_TEXT_COLOR];
    [self addSubview:signTimeTitleLabel];
    self.signTimeTitleLabel = signTimeTitleLabel;
    
    UILabel *signTimeLabel = [UILabel yyr_labelWithText:@" " fontSize:16 textColor:MAIN_TEXT_COLOR];
    [self addSubview:signTimeLabel];
    self.signTimeLabel = signTimeLabel;
}

#pragma mark - 约束
- (void)initConstraint {
    [super initConstraint];
    
    WeakSelf
    CGFloat margin = 8.0;
    CGSize oneSignImageSize = CGSizeMake([SISSPublicSingleton shared].screenWidth - 32, ([SISSPublicSingleton shared].screenWidth - 64) * 0.4);
    // 甲方
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf).offset(margin);
        make.left.equalTo(weakSelf).offset(2 * margin);
    }];
    [self.titleNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.titleLabel.mas_right);
        //        make.right.equalTo(weakSelf).offset(-2 * margin);
        make.top.equalTo(weakSelf.titleLabel);
    }];
    
    // 签名
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.titleLabel);
        make.top.equalTo(weakSelf.titleLabel.mas_bottom).offset(margin);
        make.size.mas_equalTo(oneSignImageSize);
    }];
    // 签署日期
    [self.signTimeTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.imageView);
        make.top.equalTo(weakSelf.imageView.mas_bottom).offset(margin);
        make.bottom.equalTo(weakSelf).offset(-margin);
    }];
    [self.signTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.signTimeTitleLabel.mas_right);
        make.centerY.equalTo(weakSelf.signTimeTitleLabel);
    }];

}


@end
